require 'drb/drb'
require 'logger'
require 'distributed_test_runner'
require 'drb_test_runner'

MINE_URI="druby://localhost:3344"

def logger
  logger = Logger.new(STDOUT)
  logger.level = Logger::DEBUG
  logger
end

def new_dtr_server
  server = DistributedTestRunner::Server.new
  server.packer = DistributedTestRunner::AveragePacker.new
  server.runner_name = DistributedTestRunner::RubyRunner.name
  server.test_files = ['a_test_case.rb', 'a_test_case2.rb']
  server
end

CLIENTS = ['druby://localhost:7777']

logger.info {'Initializing server...'}

SERVER = DistributedTestRunner::LoggedTestRunnerServer.new(new_dtr_server)

CLIENTS.each do |uri|
  SERVER.add_client DRbObject.new_with_uri(uri)
end

$SAFE = 1   # disable eval() and friends

logger.info {'Starting server...'}

DRb.start_service(MINE_URI, SERVER)

SERVER.run

logger.debug { SERVER.reports.to_yaml }

logger.info { "run test completed #{SERVER.succeeded? ? 'succeeded' : 'failed'}" }

